library Disarm initializer init requires LegacySystem

	private function DisarmConditions takes nothing returns boolean
		return GetSpellAbilityId()=='A01I' and GetUnitAbilityLevel(GetSpellTargetUnit(),'A03L')==0
	endfunction

	private function Disarm takes nothing returns nothing
		local unit u = GetSpellTargetUnit()
		local unit u2 = GetTriggerUnit()
		local integer id = GetUnitTypeId(u)
		call UnitAddAbility(u,'A03L')
		call PolledWait(0.5)
		call AttachSoundToUnit(gg_snd_Disarm2,u2)
		call SetSoundVolume(gg_snd_Disarm2, 80)
		call StartSound(gg_snd_Disarm2)
		if id=='n008' then
			call UnitAddItemById(u2,'I00K')
			call PolledWait(0.2)
			call RemoveUnit(u)
		elseif id=='n007' then
			call UnitAddItemById(u2,'I00L')
			call PolledWait(0.2)
			call RemoveUnit(u)
		elseif id=='n00S' or id=='n000' or id=='n00R' or id=='n00V' or id=='n013' then
			call PolledWait(0.2)
			call RemoveUnit(u)
		endif
		if u!=null then
			set u = null
		endif
		set u2 = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
		call TriggerAddCondition(t, Condition(function DisarmConditions) )
		call TriggerAddAction(t,function Disarm)
	endfunction

endlibrary